#!/usr/bin/env bash

function progress() {
    local GREEN CLEAN
    GREEN='\033[0;32m'
    CLEAN='\033[0m'
    printf "\n${GREEN}$@  ${CLEAN}\n" >&2
}

set -e

# Docker image name
IMAGENAME=registry.cn-hangzhou.aliyuncs.com/sjxxzx/purchase
DOCKER_TAG=$(date -u "+%Y%m%d-%H%M%S");

progress "Building purchase jar file ..."
mvn package -Dmaven.test.skip=true

progress "Building purchase docker image ... "
sudo docker build -t ${IMAGENAME}:${DOCKER_TAG} .

progress "login aliyun docker...."
sudo docker login --username=xxzx@3j1688 registry.cn-hangzhou.aliyuncs.com

progress "push purchase ......"
sudo docker push registry.cn-hangzhou.aliyuncs.com/sjxxzx/purchase:${DOCKER_TAG}

progress "remove purchase images......"
sudo docker rmi ${IMAGENAME}:${DOCKER_TAG}


